package com.huage.courseplatform.application.controller;
import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaIgnore;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huage.courseplatform.application.model.dto.PeriodDTO;
import com.huage.courseplatform.application.model.entity.Period;
import com.huage.courseplatform.application.model.param.PeriodPARAM;
import com.huage.courseplatform.application.service.PeriodService;
import com.huage.courseplatform.framework.api.BaseController;

import com.huage.courseplatform.framework.model.param.PagePARAM;
import com.huage.courseplatform.framework.utils.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@RestController
@RequestMapping(value = "/period")
@Api(tags = "课时接口")
@Slf4j
@SaCheckRole({"ROLE_ADMIN","ROLE_BUSINESS"})
public class PeriodController extends BaseController<Period, PeriodDTO, PeriodPARAM, PeriodService> {

    @Resource
    PeriodService periodService;

    @Override
    @SaIgnore
    @ApiOperation(value = "分页查询")
    @PostMapping(value = "/page")
    public ResultUtils<Page<PeriodDTO>> getByPage(@RequestBody PagePARAM pagePARAM){
        Page<Period> page = new Page<Period>(pagePARAM.getPageNum(),pagePARAM.getPageSize());
        QueryWrapper<Period> qw =  super.getQueryWrapperByPageParam(pagePARAM);
        periodService.periodPage(page,qw);
        return ResultUtils.success(super.entityToDto(page));
    }


    @ApiOperation(value = "绑定学生")
    @PostMapping(value = "/bindStudent")
    public ResultUtils<String> bindStudent (@RequestParam("periodId") String periodId,@RequestParam("studentId")String studentId){
        periodService.studentBindPeriod(studentId,periodId);
        return ResultUtils.success("绑定成功",null);
    }

}
